package cn.wx.scholar.core.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;

import cn.wx.common.utils.HttpResponse;
import cn.wx.common.utils.HttpUtil;
import cn.wx.common.utils.PropertiesUtil;
import cn.wx.scholar.core.entity.ResultFromYeeSight;

/**
 * 新闻社交接口
 * @author zj
 */
public class YeeSightService {
	
	private final static String yeeSightUrl = PropertiesUtil.getProperiesValue("yeesight.url", "/application.properties");
	private final static String key = "dfa95dbe9d657116c5613d6b6c05abcd";

	Logger logger = LoggerFactory.getLogger(YeeSightService.class);

	public ResultFromYeeSight getResult(String param, String type) {
		String restUrl = null;
		switch (type) {
		case "news":
			restUrl = yeeSightUrl + "/webservice/getSearchResult/" + key + "?param=" + param;
			break;
		case "social":
			restUrl = yeeSightUrl + "/webservice/getSocialSearchResult/" + key + "?param=" + param;
			break;
		}

		logger.info("my news test restUrl" + restUrl);
		
		HttpResponse httpResponse = HttpUtil.reqForGet(restUrl, null);
		
		logger.info("my news test responseCode" + httpResponse.getResponseCode());
		logger.info("my news test message" + httpResponse.getResult());
		if (httpResponse.getResponseCode() != 200) {
			return null;
		}
		ResultFromYeeSight result = JSONObject.parseObject(httpResponse.getResult(), ResultFromYeeSight.class);
		return result;
	}
}
